fix: add QMD_MAX_PARALLEL_CONTEXTS env var to prevent Metal deadlocks#569
Open
fix: add QMD_MAX_PARALLEL_CONTEXTS env var to prevent Metal deadlocks#569
Conversation
When running as an MCP server, multiple contexts calling getEmbeddingFor/rankAll via Promise.all can deadlock on macOS Metal. Setting QMD_MAX_PARALLEL_CONTEXTS=1 in the MCP config prevents this by capping context count before any GPU/CPU heuristic runs. This was already patched in dist/llm.js (production fix 2026-04-11). This commit ports the same fix to the TypeScript source so it survives the next `bun install -g @tobilu/qmd`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QMD_MAX_PARALLEL_CONTEXTSenv var check at the top ofcomputeParallelism()insrc/llm.tsQMD_MAX_PARALLEL_CONTEXTS=1), caps context count before any GPU/CPU heuristic runsgetEmbeddingFor/rankAllcalls viaPromise.allContext
This was already patched in
dist/llm.jsas a production hotfix (2026-04-11). This PR ports the identical fix to the TypeScript source so it survivesbun install -g @tobilu/qmd.The deadlock manifests on macOS with Metal GPU acceleration when multiple MCP tool calls trigger parallel embedding/reranking contexts. Setting the env var to 1 in
.mcp.jsonserializes context creation and eliminates the deadlock.Test plan
dist/llm.jspatch (identical logic)QMD_MAX_PARALLEL_CONTEXTS=1limits to 1 context🤖 Generated with Claude Code